import Vue from 'vue';//class类名
import axios from 'axios';

// 配置axios

// 1.配置实例
// axios = axios.create({
//   baseURL: '/api/',
//   // 不管延时这个选项
//   // timeout: 1000,
//   headers: {'token': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFsZXgiLCJfaWQiOiI1ZWZkM2U3NmUzM2ViNDBmNWMyZmZhMDMiLCJpYXQiOjE2MzYzNTAyNjEsImV4cCI6MTYzNjQzNjY2MX0.1fu_4SuV-zPbyTsjJzcFi5upDh4hWI75ZKjooXnHGDE'}
// });

// 2.全局配置
// axios.defaults.baseURL = '/api/';
// axios.defaults.headers.token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFsZXgiLCJfaWQiOiI1ZWZkM2U3NmUzM2ViNDBmNWMyZmZhMDMiLCJpYXQiOjE2MzYzNTAyNjEsImV4cCI6MTYzNjQzNjY2MX0.1fu_4SuV-zPbyTsjJzcFi5upDh4hWI75ZKjooXnHGDE"

// 3.拦截器  比1.2.多  配置相应
// 请求拦截
axios.interceptors.request.use(function (config) {
    // 做一些事
	// config.headers.token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InN3eCIsIl9pZCI6IjYxOGNmNGE5YTU3MTg2YWJjOGI0YWIzMiIsImlhdCI6MTYzNjc4ODA4NSwiZXhwIjoxNjM2ODc0NDg1fQ.ff_ExsL5WfRyyDcrQs3dzt7SzRp_-f9LFblGpOgJeIw"
	let user = window.localStorage.getItem('user');//{err:0,msg:'xxx',data:{},token:xxx}
	let token = user ? JSON.parse(user).token : ''
	config.headers.token = token;
    config.baseURL = "/api/";
	
	// 控制loading的显示
	return config;
  }, function (error) {
    // Do something with request error
    return Promise.reject(error);
  });

// 响应拦截
axios.interceptors.response.use(function (response) {
    // 控制loading的隐藏
	

    return response.data;
  }, function (error) {
    // Any status codes that falls outside the range of 2xx cause this function to trigger
    // Do something with response error
    return Promise.reject(error);
  });



Vue.prototype.$axios=axios;
export default axios